home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Visual C++ Utilities / Code Chameleon / Setup.exe / Setups / Chameleon / Installed / webmenu.js < prev    next >
Encoding:
JavaScript  |  2003-03-04  |  9.3 KB  |  246 lines

  1. // Copyright 2002 Angus Turnbull
  2. // Web Site: http://gusnz.cjb.net http://www.twinhelix.com/dynamic.html angus@twinhelix.com
  3. var isDOM=(document.getElementById ? true : false); 
  4. var isIE4=((document.all && !isDOM) ? true : false);
  5. var isNS4=(document.layers ? true : false);
  6. function getRef(id) 
  7. {
  8.     if(isDOM) return document.getElementById(id);
  9.     if(isIE4) return document.all[id];
  10.     if(isNS4) return document.layers[id];
  11. }
  12. function getSty(id) 
  13. {
  14.     return(isNS4 ? getRef(id) : getRef(id).style);
  15. }
  16. var popTimer=0;
  17. var litNow=new Array();
  18. function popOver(menuNum, itemNum) 
  19. {
  20.     clearTimeout(popTimer);
  21.     hideAllBut(menuNum);
  22.     litNow=getTree(menuNum, itemNum);
  23.     changeCol(litNow, true);
  24.     targetNum=menu[menuNum][itemNum].target;
  25.     if(targetNum>0) 
  26.     {
  27.     thisX=parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
  28.     thisY=parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
  29.         with(menu[targetNum][0].ref) 
  30.         {
  31.             left = parseInt(thisX + menu[targetNum][0].x);
  32.             top = parseInt(thisY + menu[targetNum][0].y);
  33.             visibility = 'visible';
  34.         }
  35.     }
  36. }
  37. function popOut(menuNum, itemNum) 
  38. {
  39.     if((menuNum==0) && !menu[menuNum][itemNum].target) hideAllBut(0)
  40.     else popTimer=setTimeout('hideAllBut(0)', 500);
  41. }
  42. function getTree(menuNum, itemNum) 
  43. {
  44.     itemArray=new Array(menu.length);
  45.     while(1) 
  46.     {
  47.         itemArray[menuNum]=itemNum;
  48.         if (menuNum==0) return itemArray;
  49.         itemNum=menu[menuNum][0].parentItem;
  50.         menuNum=menu[menuNum][0].parentMenu;
  51.     }
  52. }
  53. function changeCol(changeArray, isOver) 
  54. {
  55.     for(menuCount=0; menuCount<changeArray.length; menuCount++) 
  56.     {
  57.         if(changeArray[menuCount]) 
  58.         {
  59.         newCol=isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
  60.             with(menu[menuCount][changeArray[menuCount]].ref) 
  61.             {
  62.                 if(isNS4) bgColor=newCol;
  63.                 else backgroundColor=newCol;
  64.             }
  65.         }
  66.     }
  67. }
  68. function hideAllBut(menuNum) 
  69. {
  70.     var keepMenus=getTree(menuNum, 1);
  71.     for (count=0; count < menu.length; count++)
  72.     if (!keepMenus[count])
  73.     menu[count][0].ref.visibility='hidden';
  74.     changeCol(litNow, false);
  75. }
  76. function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) 
  77. {
  78.     this.isVert = isVert;
  79.     this.popInd = popInd
  80.     this.x = x;
  81.     this.y = y;
  82.     this.width = width;
  83.     this.overCol = overCol;
  84.     this.backCol = backCol;
  85.     this.borderClass = borderClass;
  86.     this.textClass = textClass;
  87.     this.parentMenu = null;
  88.     this.parentItem = null;
  89.     this.ref = null;
  90. }
  91. function Item(text, href, frame, length, spacing, target) 
  92. {
  93.     this.text=text;
  94.     this.href=href;
  95.     this.frame=frame;
  96.     this.length=length;
  97.     this.spacing=spacing;
  98.     this.target=target;
  99.     this.ref=null;
  100. }
  101. function writeMenus() 
  102. {
  103.     if(!isDOM && !isIE4 && !isNS4) return;
  104.     for(currMenu=0; currMenu<menu.length; currMenu++) with (menu[currMenu][0]) 
  105.     {
  106.         var str='', itemX=0, itemY=0;
  107.         for(currItem=1; currItem<menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) 
  108.         {
  109.             var itemID='menu' + currMenu + 'item' + currItem;
  110.             var w=(isVert ? width : length);
  111.             var h=(isVert ? length : width);
  112.             if(isDOM||isIE4) 
  113.             {
  114.                 str+='<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
  115.                 if(backCol) str += 'background: ' + backCol + '; ';
  116.                 str+='" ';
  117.             }
  118.             
  119.             if(isNS4) 
  120.             {
  121.                 str+='<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
  122.                 if(backCol) str+='bgcolor="' + backCol + '" ';
  123.             }
  124.  
  125.             if(borderClass) str+='class="' + borderClass + '" ';
  126.             str+='onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';
  127.         str+='<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td align="left" height="' + (h - 7) + '">' + '<a class="' + textClass + '" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') + text + '</a></td>';
  128.         if(target>0) 
  129.         {
  130.             menu[target][0].parentMenu=currMenu;
  131.             menu[target][0].parentItem=currItem;
  132.             if(popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
  133.         }        
  134.     str+='</tr></table>' + (isNS4 ? '</layer>' : '</div>');
  135.     if(isVert) itemY+= length + spacing;
  136.     else itemX+= length + spacing;
  137.     }
  138.     if(isDOM) 
  139.     {
  140.         var newDiv=document.createElement('div');
  141.         document.getElementsByTagName('body').item(0).appendChild(newDiv);
  142.         newDiv.innerHTML=str;
  143.         ref=newDiv.style;
  144.         ref.position='absolute';
  145.         ref.visibility='hidden';
  146.     }
  147.     if(isIE4) 
  148.     {
  149.         document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
  150.         ref=getSty('menu' + currMenu + 'div');
  151.     }
  152.     if(isNS4) 
  153.     {
  154.     ref=new Layer(0);
  155.     ref.document.write(str);
  156.     ref.document.close();
  157.     }
  158.     for(currItem=1; currItem<menu[currMenu].length; currItem++) 
  159.     {
  160.         itemName= 'menu' + currMenu + 'item' + currItem;
  161.         if(isDOM || isIE4) menu[currMenu][currItem].ref = getSty(itemName);
  162.         if(isNS4) menu[currMenu][currItem].ref = ref.document[itemName];
  163.     }
  164.   }    
  165.     with(menu[0][0]) 
  166.     {
  167.         ref.left = x;
  168.         ref.top = y;
  169.         ref.visibility = 'visible';
  170.        }
  171. }
  172.  
  173. //{{COLORDEF
  174. function MenuInit(){document.write('<TABLE cellSpacing=0 cellPadding=0 width="100%" bgColor=#D4E3FF border=0><TBODY><TR><TD height=17><FONT size=1> </FONT></TD></TR></TBODY></TABLE>');}
  175. var TopOver='#68A9DD';
  176. var TopBg='#D4E3FF';
  177. var L1Over='#6CB6FF';
  178. var L1Bg='#2E88D1';
  179. var L2Over='#91C8FF';
  180. var L2Bg='#73A8F7';
  181. //}}COLORDEF
  182.  
  183. //{{MENUDEF
  184. var menu = new Array();
  185. menu[0] = new Array();
  186. menu[0][0] = new Menu(true,'', 15, 15, 120, TopOver, TopBg,'TopStripBorder','TopStripText');
  187. menu[0][1] = new Item('C Point','#','',    20,4,1);
  188. menu[1] = new Array();
  189. menu[1][0] = new Menu(true,'',122,0,130,L2Over,L2Bg,'Level2Border','Level2Text');
  190. menu[1][1] = new Item('Home','http://www.c-point.com/index.html','',    22,0,0);
  191. menu[1][2] = new Item('Company profile','http://www.c-point.com/profile.htm','',    22,0,0);
  192. menu[1][3] = new Item('Distributors','http://www.c-point.com/distributors.htm','',    22,0,0);
  193. menu[1][4] = new Item('License agreement','http://www.c-point.com/license.htm','',    22,0,0);
  194. menu[1][5] = new Item('E-mail policy','http://www.c-point.com/policy.htm','',    22,0,0);
  195. menu[1][6] = new Item('Our guarantee','http://www.c-point.com/guarantee.htm','',    22,0,0);
  196. menu[0][2] = new Item('Support','#','',    20,4,2);
  197. menu[2] = new Array();
  198. menu[2][0] = new Menu(true,'',122,0,140,L2Over,L2Bg,'Level2Border','Level2Text');
  199. menu[2][1] = new Item('FAQ','http://www.c-point.com/support2.htm','',   22,0,0);
  200. menu[2][2] = new Item('Customer comments','http://www.c-point.com/customer.htm','',   22,0,0);
  201. menu[2][3] = new Item('Join Mailing List','http://www.c-point.com/mailinglist.htm','',   22,0,0);
  202. menu[2][4] = new Item('Contact us','http://www.c-point.com/support2.htm','',   22,0,0);
  203. menu[0][3] = new Item('Discussion board','#','',    20,4,3);
  204. menu[3] = new Array();
  205. menu[3][0] = new Menu(true,'',122,0,130,L2Over,L2Bg,'Level2Border','Level2Text');
  206. menu[3][1] = new Item('Member log in','http://www.c-point.com/cpboard/index.html','',   22,0,0);
  207. menu[3][2] = new Item('Join','http://www.c-point.com/cpboard/index.html','',   22,0,0);
  208. menu[0][4] = new Item('Tools','#','',    20,4,4);
  209. menu[4] = new Array();
  210. menu[4][0] = new Menu(true,'',122,0,130,L2Over,L2Bg,'Level2Border','Level2Text');
  211. menu[4][1] = new Item('Programming','#','',   22,0,5);
  212. menu[5] = new Array();
  213. menu[5][0] = new Menu(true,'',132,0,150,L2Over,L2Bg,'Level2Border','Level2Text');
  214. menu[5][1] = new Item('Antechinus C# Editor','http://www.c-point.com/csharp.htm','',  22,0,0);
  215. menu[5][2] = new Item('Antechinus JavaScript Editor','http://www.c-point.com/pjedit.htm','',  22,0,0);
  216. menu[4][2] = new Item('Animation','#','',   22,0,6);
  217. menu[6] = new Array();
  218. menu[6][0] = new Menu(true,'',132,0,130,L2Over,L2Bg,'Level2Border','Level2Text');
  219. menu[6][1] = new Item('Antechinus Animator','http://www.c-point.com/animator.htm','',  22,0,0);
  220. menu[6][2] = new Item('Antechinus Media Editor','http://www.c-point.com/mediaed.htm#ame','',  22,0,0);
  221. menu[4][3] = new Item('Multimedia','#','',   22,0,7);
  222. menu[7] = new Array();
  223. menu[7][0] = new Menu(true,'',132,0,150,L2Over,L2Bg,'Level2Border','Level2Text');
  224. menu[7][1] = new Item('Antechinus Media Editor','http://www.c-point.com/mediaed.htm#ame','',    20,0,0);
  225. menu[4][4] = new Item('Web development','#','',   22,0,8);
  226. menu[8] = new Array();
  227. menu[8][0] = new Menu(true,'',132,0,160,L2Over,L2Bg,'Level2Border','Level2Text');
  228. menu[8][1] = new Item('Antechinus Web Effects','http://www.c-point.com/webeffects.htm','',  22,0,0);
  229. menu[8][2] = new Item('Antechinus JavaScript Editor','http://www.c-point.com/pjedit.htm','',  22,0,0);
  230. menu[0][5] = new Item('Download','http://www.c-point.com/download2.htm','',    20,4,0);
  231. menu[0][6] = new Item('Order','http://www.c-point.com/secure2.htm','',    20,4,0);
  232. //}}MENUDEF
  233.  
  234. var popOldWidth=window.innerWidth;
  235. nsResizeHandler=new Function('if (popOldWidth != window.innerWidth) location.reload()');
  236. if(isNS4) document.captureEvents(Event.CLICK);
  237. document.onclick=clickHandle;
  238. function clickHandle(evt){if (isNS4) document.routeEvent(evt);    hideAllBut(0);}
  239. function moveRoot(){with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);}
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.